PSCI: Add deprecated API for SPD when compatibility is disabled
authorSoby Mathew <[email protected]>
Mon, 13 Jul 2015 15:26:11 +0000 (16:26 +0100)
committerAchin Gupta <[email protected]>
Thu, 13 Aug 2015 22:48:06 +0000 (23:48 +0100)
This patch defines deprecated platform APIs to enable Trusted
Firmware components like Secure Payload and their dispatchers(SPD)
to continue to build and run when platform compatibility is disabled.
This decouples the migration of platform ports to the new platform API
from SPD and enables them to be migrated independently. The deprecated
platform APIs defined in this patch are : platform_get_core_pos(),
platform_get_stack() and platform_set_stack().

The patch also deprecates MPIDR based context management helpers like
cm_get_context_by_mpidr(), cm_set_context_by_mpidr() and cm_init_context().
A mechanism to deprecate APIs and identify callers of these APIs during
build is introduced, which is controlled by the build flag WARN_DEPRECATED.
If WARN_DEPRECATED is defined to 1, the users of the deprecated APIs will be
flagged either as a link error for assembly files or compile time warning
for C files during build.

Change-Id: Ib72c7d5dc956e1a74d2294a939205b200f055613

Makefile
docs/user-guide.md
include/bl31/context_mgmt.h
include/common/asm_macros.S
include/plat/common/common_def.h
include/plat/common/platform.h
plat/common/aarch64/plat_common.c
plat/common/aarch64/platform_helpers.S
plat/common/aarch64/platform_mp_stack.S
plat/common/aarch64/platform_up_stack.S

index 2120cb3fcb6edced25c2decbecf6e22d77be09c5..050a76e2051be3c3974c45234209888b95543222 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,8 @@ TRUSTED_BOARD_BOOT    := 0
 # By default, consider that the platform's reset address is not programmable.
 # The platform Makefile is free to override this value.
 PROGRAMMABLE_RESET_ADDRESS     := 0
+# Build flag to warn about usage of deprecated platform and framework APIs
+WARN_DEPRECATED        := 0
 
 # Checkpatch ignores
 CHECK_IGNORE           =       --ignore COMPLEX_MACRO \
@@ -302,6 +304,10 @@ $(eval $(call add_define,PROGRAMMABLE_RESET_ADDRESS))
 $(eval $(call assert_boolean,ENABLE_PLAT_COMPAT))
 $(eval $(call add_define,ENABLE_PLAT_COMPAT))
 
+# Process WARN_DEPRECATED flag
+$(eval $(call assert_boolean,WARN_DEPRECATED))
+$(eval $(call add_define,WARN_DEPRECATED))
+
 ASFLAGS                        +=      -nostdinc -ffreestanding -Wa,--fatal-warnings   \
                                -Werror -Wmissing-include-dirs                  \
                                -mgeneral-regs-only -D__ASSEMBLY__              \
index ad8d1c748f481387a4211224cefcacd6d8d6153d..5be3c3dc1ac42049abe5cf3a69d3b6b8ca2e74bb 100644 (file)
@@ -362,6 +362,11 @@ performed.
     and it governs the return value of PSCI_FEATURES API for CPU_SUSPEND
     smc function id.
 
+*   `WARN_DEPRECATED`: This option decides whether to warn the usage of
+    deprecated platform APIs and context management helpers within Trusted
+    Firmware. It can take the value 1 (warn the use of deprecated APIs) or
+    0. The default is 0.
+
 #### ARM development platform specific build options
 
 *   `ARM_TSP_RAM_LOCATION`: location of the TSP binary. Options:
index 7e9fe832c43c500e1e54f99eb939a760b2f3b793..1ef40766bcf7b168625dd6a974ada2d2a3a4d250 100644 (file)
@@ -31,6 +31,7 @@
 #ifndef __CM_H__
 #define __CM_H__
 
+#include <common_def.h>
 #include <cpu_data.h>
 #include <stdint.h>
 
@@ -43,18 +44,20 @@ struct entry_point_info;
  * Function & variable prototypes
  ******************************************************************************/
 void cm_init(void);
-void *cm_get_context_by_mpidr(uint64_t mpidr, uint32_t security_state);
+void *cm_get_context_by_mpidr(uint64_t mpidr,
+                             uint32_t security_state) __warn_deprecated;
 static inline void *cm_get_context(uint32_t security_state);
 void cm_set_context_by_mpidr(uint64_t mpidr,
                             void *context,
-                            uint32_t security_state);
+                            uint32_t security_state) __warn_deprecated;
 void *cm_get_context_by_index(unsigned int cpu_idx,
                              unsigned int security_state);
 void cm_set_context_by_index(unsigned int cpu_idx,
                             void *context,
                             unsigned int security_state);
 static inline void cm_set_context(void *context, uint32_t security_state);
-void cm_init_context(uint64_t mpidr, const struct entry_point_info *ep);
+void cm_init_context(uint64_t mpidr,
+                    const struct entry_point_info *ep) __warn_deprecated;
 void cm_init_my_context(const struct entry_point_info *ep);
 void cm_init_context_by_index(unsigned int cpu_idx,
                              const struct entry_point_info *ep);
index f959eb4f9e37592310673f12c04428a8cff81a17..128259f1940ab04cb6788ed925a9cdd15e67830a 100644 (file)
        .size \_name, . - \_name
        .endm
 
+       /*
+        * Theses macros are used to create function labels for deprecated
+        * APIs. If WARN_DEPRECATED is non zero, the callers of these APIs
+        * will fail to link and cause build failure.
+        */
+#if WARN_DEPRECATED
+       .macro func_deprecated _name
+       func deprecated\_name
+       .endm
+
+       .macro endfunc_deprecated _name
+       endfunc deprecated\_name
+       .endm
+#else
+       .macro func_deprecated _name
+       func \_name
+       .endm
+
+       .macro endfunc_deprecated _name
+       endfunc \_name
+       .endm
+#endif
+
        /*
         * This macro declares an array of 1 or more stacks, properly
         * aligned and in the requested section
index 1b3203e12ebae9efb5704a7c1ca6337d438eec89..077080df3b40c0dcdb7648a9e6e1d9b236be9342 100644 (file)
   #define MAKE_ULL(x)                  x
 #endif
 
+/*
+ * Macros to wrap declarations of deprecated APIs within Trusted Firmware.
+ * The callers of these APIs will continue to compile as long as the build
+ * flag WARN_DEPRECATED is zero. Else the compiler will emit a warning
+ * when the callers of these APIs are compiled.
+ */
+#if WARN_DEPRECATED
+#define __warn_deprecated      __attribute__ ((deprecated))
+#else
+#define __warn_deprecated
+#endif
 
 #endif /* __COMMON_DEF_H__ */
 
index f054cd0a20da429ff7b6b1dd8781bc34afe38a0b..8071f39424c1ce325fdcf6f1b0f1204da19edf75 100644 (file)
@@ -228,6 +228,13 @@ int platform_setup_pm(const plat_pm_ops_t **);
 
 unsigned int plat_get_aff_count(unsigned int, unsigned long);
 unsigned int plat_get_aff_state(unsigned int, unsigned long);
-#endif /* __ENABLE_PLAT_COMPAT__ */
+#else
+/*
+ * The below function enable Trusted Firmware components like SPDs which
+ * haven't migrated to the new platform API to compile on platforms which
+ * have the compatibility layer disabled.
+ */
+unsigned int platform_get_core_pos(unsigned long mpidr) __warn_deprecated;
 
+#endif /* __ENABLE_PLAT_COMPAT__ */
 #endif /* __PLATFORM_H__ */
index 90574fd6642fa70f1607bf6365a113521500dc79..a6a8476557dc53e3706634a20879368964865953 100644 (file)
@@ -27,7 +27,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include <assert.h>
+#include <platform.h>
 #include <xlat_tables.h>
 
 /*
@@ -47,3 +48,18 @@ void bl32_plat_enable_mmu(uint32_t flags)
 {
        enable_mmu_el1(flags);
 }
+
+#if !ENABLE_PLAT_COMPAT
+/*
+ * Helper function for platform_get_pos() when platform compatibility is
+ * disabled. This is to enable SPDs using the older platform API to continue
+ * to work.
+ */
+unsigned int platform_core_pos_helper(unsigned long mpidr)
+{
+       int idx = plat_core_pos_by_mpidr(mpidr);
+       assert(idx >= 0);
+       return idx;
+}
+#endif
+
index b88603c37089d4f012342ddde0591a9936f8196c..9f4b672ab8c7de4ec50466ec36d673108f6d1012 100644 (file)
        .weak   plat_reset_handler
        .weak   plat_disable_acp
 
+#if !ENABLE_PLAT_COMPAT
+       .globl  platform_get_core_pos
+
+#define MPIDR_RES_BIT_MASK     0xff000000
+
+       /* ------------------------------------------------------------------
+        *  int platform_get_core_pos(int mpidr)
+        *  Returns the CPU index of the CPU specified by mpidr. This is
+        *  defined when platform compatibility is disabled to enable Trusted
+        *  Firmware components like SPD using the old  platform API to work.
+        *  This API is deprecated and it assumes that the mpidr specified is
+        *  that of a valid and present CPU. Instead, plat_my_core_pos()
+        *  should be used for CPU index of the current CPU and
+        *  plat_core_pos_by_mpidr() should be used for CPU index of a
+        *  CPU specified by its mpidr.
+        * ------------------------------------------------------------------
+        */
+func_deprecated platform_get_core_pos
+       bic     x0, x0, #MPIDR_RES_BIT_MASK
+       mrs     x1, mpidr_el1
+       bic     x1, x1, #MPIDR_RES_BIT_MASK
+       cmp     x0, x1
+       beq     plat_my_core_pos
+       b       platform_core_pos_helper
+endfunc_deprecated platform_get_core_pos
+#endif
+
        /* -----------------------------------------------------
         * Placeholder function which should be redefined by
         * each platform.
index 6cfa0697b4e1c1664800cbed1d4dd82c90e18e44..c719019ac4736deedc6cc4c41755e443f48f7dda 100644 (file)
@@ -42,8 +42,9 @@
 #else
        .weak   plat_get_my_stack
        .weak   plat_set_my_stack
-#endif /*__ENABLE_PLAT_COMPAT__*/
-
+       .globl  platform_get_stack
+       .globl  platform_set_stack
+#endif /* __ENABLE_PLAT_COMPAT__ */
 
 #if ENABLE_PLAT_COMPAT
        /* ---------------------------------------------------------------------
@@ -108,6 +109,54 @@ func platform_set_stack
 endfunc platform_set_stack
 
 #else
+       /* ---------------------------------------------------------------------
+        * When the compatility layer is disabled, the new platform APIs
+        * viz plat_get_my_stack() and plat_set_my_stack() are
+        * supported by the platform and the previous APIs platform_get_stack()
+        * and platform_set_stack() are defined in terms of new APIs making use
+        * of the fact that they are only ever invoked for the current CPU.
+        * This is to enable components of Trusted Firmware like SPDs using the
+        * old platform APIs to continue to work.
+        * --------------------------------------------------------------------
+        */
+
+       /* -------------------------------------------------------
+        * unsigned long platform_get_stack (unsigned long mpidr)
+        *
+        * For the current CPU, this function returns the stack
+        * pointer for a stack allocated in device memory. The
+        * 'mpidr' should correspond to that of the current CPU.
+        * This function is deprecated and plat_get_my_stack()
+        * should be used instead.
+        * -------------------------------------------------------
+        */
+func_deprecated platform_get_stack
+#if ASM_ASSERTION
+       mrs     x1, mpidr_el1
+       cmp     x0, x1
+       ASM_ASSERT(eq)
+#endif
+       b       plat_get_my_stack
+endfunc_deprecated platform_get_stack
+
+       /* -----------------------------------------------------
+        * void platform_set_stack (unsigned long mpidr)
+        *
+        * For the current CPU, this function sets the stack pointer
+        * to a stack allocated in normal memory. The
+        * 'mpidr' should correspond to that of the current CPU.
+        * This function is deprecated and plat_get_my_stack()
+        * should be used instead.
+        * -----------------------------------------------------
+        */
+func_deprecated platform_set_stack
+#if ASM_ASSERTION
+       mrs     x1, mpidr_el1
+       cmp     x0, x1
+       ASM_ASSERT(eq)
+#endif
+       b       plat_set_my_stack
+endfunc_deprecated platform_set_stack
 
        /* -----------------------------------------------------
         * unsigned long plat_get_my_stack ()
index d6d6c6e22368a3aa856ef116a4795fa4053e7b3f..c01534af5f3f48fe4eebc856170c825f995150ee 100644 (file)
@@ -41,7 +41,6 @@
 
        /* -----------------------------------------------------
         * unsigned long plat_get_my_stack ()
-        * unsigned long platform_get_stack (unsigned long)
         *
         * For cold-boot BL images, only the primary CPU needs a
         * stack. This function returns the stack pointer for a
         * -----------------------------------------------------
         */
 func plat_get_my_stack
-platform_get_stack:
        get_up_stack platform_normal_stacks, PLATFORM_STACK_SIZE
        ret
 endfunc plat_get_my_stack
 
        /* -----------------------------------------------------
         * void plat_set_my_stack ()
-        * void platform_set_stack (unsigned long)
         *
         * For cold-boot BL images, only the primary CPU needs a
         * stack. This function sets the stack pointer to a stack
@@ -64,12 +61,37 @@ endfunc plat_get_my_stack
         * -----------------------------------------------------
         */
 func plat_set_my_stack
-platform_set_stack:
        get_up_stack platform_normal_stacks, PLATFORM_STACK_SIZE
        mov sp, x0
        ret
 endfunc plat_set_my_stack
 
+       /* -----------------------------------------------------
+        * unsigned long platform_get_stack ()
+        *
+        * For cold-boot BL images, only the primary CPU needs a
+        * stack. This function returns the stack pointer for a
+        * stack allocated in device memory. This function
+        * is deprecated.
+        * -----------------------------------------------------
+        */
+func_deprecated platform_get_stack
+       b       plat_get_my_stack
+endfunc_deprecated platform_get_stack
+
+       /* -----------------------------------------------------
+        * void platform_set_stack ()
+        *
+        * For cold-boot BL images, only the primary CPU needs a
+        * stack. This function sets the stack pointer to a stack
+        * allocated in normal memory.This function is
+        * deprecated.
+        * -----------------------------------------------------
+        */
+func_deprecated platform_set_stack
+       b       plat_set_my_stack
+endfunc_deprecated platform_set_stack
+
        /* -----------------------------------------------------
         * Single cpu stack in normal memory.
         * Used for C code during boot, PLATFORM_STACK_SIZE bytes